﻿@{
    Layout = null;
}
<script src="@Url.Content("~/Scripts/jquery-1.8.3.min.js")"></script>
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>列表页</title>
</head>
<body>
    <div>
        <table id="dtTable" style="width: 100%" border="1">
            <tr>
                <th>名称</th>
                <th>二维码</th>
                <th>操作</th>
            </tr>
        </table>
    </div>
</body>
</html>

<script type="text/javascript">

    $(function () {
        getData();
        initEvent();
    });

    function getData() {
        $.ajax({
            url: "@Url.Action("GetList", "JiaWeiXinQun")",
            type: "post",
            data: {},
            dataType: "json",
            success: function (dt) {
                $("#dtTable tr:gt(0)").remove();
                var dtTable = $("#dtTable");
                var list = dt;
                for (var i = 0; i < list.length; i++) {
                    var newTr;
                    if (list[i].Statu == 0) {
                        newTr = $("<tr><td>" + list[i].QunName + "</td><td>" + list[i].twoCodeUrl + "</td><td><input value='启用' type='button' class='qiyong' ID='" + list[i].ID + "' imgUrl='" + list[i].twoCodeUrl + "' /><input value='删除' type='button' class='shanchu' ID='" + list[i].ID + "'/></td></tr>")
                    } else {
                        newTr = $("<tr style='background-color:red'><td>" + list[i].QunName + "</td><td>" + list[i].twoCodeUrl + "</td><td>启用中 </td></tr>")
                    }
                    dtTable.append(newTr);
                }
            }
        });
    }

    function initEvent() {
        $(".qiyong").live("click", function () {
            if (confirm("确定启用吗？")) {
                var Id = $(this).attr("Id");
                var imgUrl = $(this).attr("imgUrl");
                $.ajax({
                    url: "@Url.Action("QiYong", "JiaWeiXinQun")",
                    type: "post",
                    data: { Id: Id, imgUrl: imgUrl },
                    dataType: "json",
                    success: function (d) {
                        if (d == "1") {
                            alert("启用成功");
                            getData();
                        } else {
                            alert("启用失败");
                        }
                    }
                });
            }
        });

        $(".shanchu").live("click", function () {
            if (confirm("确定删除吗？")) {
                var Id = $(this).attr("Id");
             
                $.ajax({
                    url: "@Url.Action("ShanChu", "JiaWeiXinQun")",
                    type: "post",
                    data: { Id: Id },
                    dataType: "json",
                    success: function (d) {
                        if (d == "1") {
                            alert("启用成功");
                            getData();
                        } else {
                            alert("启用失败");
                        }
                    }
                });
            }
        });


    }



</script>
